FROM node:14 AS build
WORKDIR /app

# 增加Node内存限制
ENV NODE_OPTIONS="--max-old-space-size=4096"

# 设置镜像源和缓存策略
RUN npm config set registry https://registry.npmmirror.com && \
    npm cache clean --force

# 先仅复制package文件，提高缓存效率
COPY package*.json ./

# 安装依赖
RUN npm install --legacy-peer-deps || \
    (npm cache clean --force && npm install --legacy-peer-deps)

# 复制其他所有文件
COPY . .

# 修复可能存在的依赖问题
RUN npm install vuex@4.1.0 --legacy-peer-deps --no-audit

# 构建应用
RUN npm run build

FROM nginx:alpine
WORKDIR /usr/share/nginx/html
COPY --from=build /app/dist .
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"] 